package com.pai4j.common.bean;

import com.pai4j.common.enums.ResponseCodeEnum;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;

/**
 *  统一响应工具类
 *
 * @author: CYM-pai
 * @date: 2025/04/15 16:43
 **/

@Data
public class PAIResponseBeanUtil {
   
    /**
     * 构建成功结果
     *
     * @author: CYM-pai
     * @date: 2025/04/15 16:51
     **/
    public static PAIResponseBean success(Object data){
         PAIResponseBean paiResponseBean = new PAIResponseBean<>();
         paiResponseBean.setSuccess(true);
         paiResponseBean.setCode(ResponseCodeEnum.SUCCESS.getCode());
         paiResponseBean.setMessage("OK");
         paiResponseBean.setData(data);
         return paiResponseBean;
    }
    
    /**
     * 构建无数据的成功结果
     *
     * @author: CYM-pai
     * @date: 2025/04/15 21:06
     **/
    
    public static PAIResponseBean success(){
      return success(null);
    }
    
    /**
     *  构建失败的结果
     *
     * @author: CYM-pai
     * @date: 2025/04/15 21:08
     **/
    
    public static PAIResponseBean error(Integer code, String message){
        PAIResponseBean paiResponseBean = new PAIResponseBean();
        paiResponseBean.setSuccess(false);
        paiResponseBean.setCode(code);
        paiResponseBean.setMessage(message);
        return paiResponseBean;
    }
    
    /**
     * 检验返回结果是否成功
     *
     * @author: CYM-pai
     * @date: 2025/04/15 21:13
     **/
    public static boolean isOk(PAIResponseBean paiResponseBean){
        //paiResponseBean不为空并且paiResponseBean.getSuccess() == true
        return paiResponseBean != null && ObjectUtils.equals(paiResponseBean.getSuccess(),true);
    }
    
}
